package com.springapp.mvc;

import com.springapp.mvc.entiry.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/")
public class HelloController {

	@RequestMapping(method = RequestMethod.GET, headers = "Accept=*/*")
	public
	@ResponseBody
	List<User> printWelcome(ModelMap model) {
		User user = new User();
		user.setId(11111);
		user.setName("dsdsfdsf");
		List list = new ArrayList();
		list.add(user);
		list.add(user);
		list.add(user);
		return list;
	}

	@RequestMapping(method = RequestMethod.GET, value = "/map")
	public
	@ResponseBody
	Map print0Welcome(ModelMap model) {
		User user = new User();
		user.setId(1133111);
		user.setName("dsdsfd444sf");
		Map list = new HashMap();
		list.put(1, user);
		list.put(3, user);
		list.put(2, user);
		return list;
	}

	@RequestMapping(method = RequestMethod.POST, value = "/map", consumes = "application/json")
	public
	@ResponseBody
	User save(@RequestBody User user) {
		return user;
	}

}